<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="../utils/js/old_version/react.development.js"></script>
    <script src="../utils/js/old_version/react-dom.development.js"></script>
    <script src="../utils/js/old_version/babel.min.js"></script>
    <script src="../utils/js/old_version/prop-types.js"></script>
    <script type="text/babel">
      class Demo extends React.Component {
        state = {
          isHot: false,
        };

        alert1 = () => {
          console.log(this);
          let input1 = this.refs;
          alert(input1.value);
        };

        alert2 = () => {
          let { input2 } = this.refs; // 获取真实的dom
          alert(input2.value);
        };

        alert3 = () => {
          let { input1 } = this;
          alert(input1.value);
        };

        saveInput = (currentNode) => {
          this.input1 = currentNode;
          console.log(currentNode);
        };

        changeHot = () => {
          const { isHot } = this.state;
          this.setState({ isHot: !isHot });
        };

        render() {
          // 字符串的ref 最老的写法，已不推荐了  写多了效率就不高了
          // return (
          //   <div>
          //     <input type="text" placeholder="点击弹值" ref="input1" /> &nbsp;
          //     <span onClick={this.alert1}>点击弹左边的值</span>&nbsp;&nbsp;
          //     <input
          //       type="text"
          //       placeholder="失去焦点弹值"
          //       ref="input2"
          //       onBlur={this.alert2}
          //     />
          //   </div>
          // );

          // 把 ref 当前所处的节点挂在了实例自身上并且取了个名字叫 input1

          const { isHot } = this.state;
          return (
            <div>
              {/* <input
                type="text"
                placeholder="点击弹值"
                ref={(currentNode) => (this.input1 = currentNode)}
              /> */}
              <input type="text" placeholder="点击弹值" ref={this.saveInput} />
              &nbsp;
              <span onClick={this.alert3}>点击弹左边的值</span>
              <br />
              <div>今天天气很{isHot ? "热" : "冷"}</div>
              <div onClick={this.changeHot}>切换天气</div>
            </div>
          );
        }
      }

      ReactDOM.render(<Demo />, document.getElementById("app"));
    </script>
  </body>
</html>
